import { Component, Inject, Injector, ViewChild } from '@angular/core';
import { DesktopCmpComponent } from "../../component/desktop-cmp/desktop-cmp.component";
import { BackgroundCmpComponent } from "../../component/background-cmp/background-cmp.component";
import { TaskbarCmpComponent } from "../../component/taskbar-cmp/taskbar-cmp.component";
import { ActionHandlerService } from '../../service/action-handler.service';
import { ActivatedRoute, NavigationExtras, Route, Router } from '@angular/router';
 

@Component({
  selector: 'app-home-page',
  standalone: true, 
  imports: [DesktopCmpComponent, BackgroundCmpComponent, TaskbarCmpComponent],
  templateUrl: './home-page.component.html',
  styleUrl: './home-page.component.sass'
})
export class HomePageComponent {

  constructor(private actionSvc: ActionHandlerService, private route: ActivatedRoute,private router: Router  ) { 
  }
  ngOnInit(): void { 
 
  }
 

  ngAfterViewInit(): void {
    this.route.queryParams.subscribe(async params => {
      const action = params['action']; 
      if (action) {
        await this.actionSvc.handleAction(action, params); 
        this.clearQueryParams();
      }
    });
  }
  

  clearQueryParams(): void {
    // 获取当前路由的路径（保留路径，清除查询参数）
    const navigationExtras: NavigationExtras = {
      queryParams: {}, // 空对象表示清除所有查询参数
    };
 
    this.router.navigate([], navigationExtras);
  }

}

  
